package stack.era.presentation.world;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerListModel;
import javax.swing.SpinnerModel;

public class WorldExploreTab extends JPanel {

	private static final long serialVersionUID = 4599755580371001811L;

	private String[] spinnerValues;

	private JButton exploreButton;
	private JSpinner hoursSpinner;

	public WorldExploreTab(WorldPanel callback) {
		super();

		spinnerValues = new String[12];
		for (int i = 0; i < spinnerValues.length; i++) {
			spinnerValues[i] = (i + 1) + " Hours";
		}

		exploreButton = new JButton("Explore The World");
		exploreButton.addActionListener(new ExploreControl(this, callback));
		exploreButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
		SpinnerModel model = new SpinnerListModel(spinnerValues);
		hoursSpinner = new JSpinner(model);
		JFormattedTextField tf = ((JSpinner.DefaultEditor) hoursSpinner
				.getEditor()).getTextField();
		tf.setEditable(false);
		tf.setBackground(Color.WHITE);

		JPanel content = new JPanel();
		content.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
		content.setLayout(new GridLayout(1, 2));
		content.add(hoursSpinner);
		content.add(exploreButton);

		this.setLayout(new BorderLayout());
		this.setBorder(BorderFactory.createLineBorder(Color.GRAY, 200));
		this.add(content, BorderLayout.CENTER);
	}

	public int getHoursOnSpinner() {
		for (int i = 0; i < spinnerValues.length; i++) {
			if (((String) hoursSpinner.getValue()).equals(spinnerValues[i])) {
				return i + 1;
			}
		}
		return 0;
	}

	public void explore() {
		// Use hoursToExplore to determine what was found

	}

}
